import time

from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.common.touch_action import TouchAction

url = "http://127.0.0.1:4723/wd/hub"

param = {
  "deviceName": "127.0.0.1:62001",   # 设备号·
  "platformName": "Android",     # 系统名称
  "platformVersion": "7.1.2",    # 系统版本
  "appPackage": "com.meituan.phoenix",   # 软件包名
  "appActivity": "com.meituan.phoenix.MainActivity"   # 启动类名
}

driver = webdriver.Remote(url,param)
driver.implicitly_wait(60)
# 开发脚本27
# 增强脚本：1.将旧的api方法替换最新的方式  2.添加等待方式
# time.sleep(2)
el1 = driver.find_element(MobileBy.ID,"com.meituan.phoenix:id/btn_choice_city")
el1.click()
# time.sleep(5)
el2 = driver.find_element(MobileBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[1]/android.view.ViewGroup/android.widget.ScrollView/android.view.ViewGroup/android.view.ViewGroup[1]/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[9]")
el2.click()
# time.sleep(2)
el3 = driver.find_element(MobileBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[2]/android.widget.EditText")
el3.click()
# time.sleep(2)
el3.send_keys("北京")
time.sleep(5)
el4 = driver.find_element(MobileBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.widget.ScrollView/android.view.ViewGroup/android.view.ViewGroup[1]/android.view.ViewGroup[1]")
el4.click()
time.sleep(10)
for i in range(5):
    time.sleep(2)
    TouchAction(driver).long_press(x=395, y=1250).move_to(x=405, y=583).release().perform()

time.sleep(10)
driver.quit()


